A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
This invention relates generally to object oriented programming languages and more particularly to a system and method for joining a plurality of type hierarchies in an object oriented programming language.
Object oriented programming languages, such as C++, Objective C, Java, SmallTalk, Object Pascal and others, have become the tools of choice in modern software engineering practice. These languages enable programmers to define classes of objects which can be more readily adapted to specific software applications than previously possible with control flow programming languages. And object class libraries result in better structured code and lower development costs.
Often, to achieve code minimization, clarity and maintainability, object class functions must be written to transparently operate over a variety of concrete data types. In C++, for instance, if two data types (or classes) are related by inheritance, a function can be written to receive a reference to an instance of the derived class as a reference to the common base class. Operations on the base class, though, can be overridden in the derived class so the reference appears to be polymorphic. For polymorphic functions, the behavior of the invoked method becomes dependent upon the data type of the referenced object, including whether the referenced object is considered to be constant, and not on the data type of the static reference.
In addition, many languages allow const'ness overloading whereby functions can be declared as being applicable to constant or nonconstant instances. Const'ness overloading is an attractive feature for ensuring proper function referencing, such as ensuring that a function which modifies an object is not called on an object which should not be modified. However, often the underlying language does not support compiler maintenance of const'ness overloading, such as in the Java programming language.
In many object oriented programming languages, including C++, related problems exist with supporting polymorphic functions which must operate over primitive data types which, not being considered instances of classes, cannot have a common base class or instances of classes within type hierarchies not unified by a common base class. The latter case is particularly problematic when the class declarations cannot be modified. These problems often occur with class libraries from third parties, such as external vendors.
One prior art solution uses function overloading, such as described in M. A. Ellis & B. Stroustrup, "The Annotated C++ Reference Manual," pp. 307-340, 1990, the disclosure of which is incorporated herein by reference. However, this solution suffers from several drawbacks. First, function overloading requires a separate function implementation for each supported primitive type, thereby leading to code duplication and increased code maintenance. Also, function return types cannot be overloaded in many languages, such as C++, and therefore a result must be implemented as an additional parameter on the function call with an adverse effect on the "naturalness" of the code.
Another prior art solution uses templated functions, member functions and classes, such as described in S. Meyers, "Effective C++," pp. 184-191, 1992, the disclosure of which is incorporated herein by reference. This solution also suffers from several drawbacks. First, templated member functions are not currently supported by most C++ compilers which therefore limits their applicability. Second, this solution improves code maintenance at the expense of code exposure, as most compilers require the implementation of each templated class or function to be visible to the client that uses it. Third, the template must generally be specialized for "primitive" classes, such as described in S. Meyers, "More Effective C++," pp. 159-182, 1996, the disclosure of which is incorporated herein by reference. Moreover, if there are N parameters for each specialization which can each take on K possible data types, N.times.K specializations must be written or implicitly generated. Fourth, the caller function must statically determine the types of the arguments.
A further prior art solution uses "smart pointer classes" for overloading member functions based on const and non-const arguments, also referred to as "const 'ness," such as described in S. Meyers, "More Effective C++," pp. 181-182, 1996. This solution defines two pointer classes: (1) a pointer-to-const-T class; and (2) a pointer-to-non-const-T class derived from the pointer-to-const-T class. However, this solution is directed to the issue of reference counted pointers and not merging type hierarchies or specializations based on data type primitives. Moreover, this solution fails if the type of an outbound argument is determined as part of the operation of the function, such as determining whether an integer argument is long or double.
Yet a further prior art solution uses a tagged union of pointers for arguments supporting multiple data types. This solution requires the use of both a union discriminator for indicating the data type of the referenced argument and the data value of the union itself. Both items must be passed or returned. A problem with this solution is the effect on the naturalness of the code. Instead of directly calling a function, the union must be created and assigned. Moreover, if a function caller receives a union as the output parameter, to use the result, the function caller must determine the data type contained in the received union, typically through the use of a lengthy switch or comparison statement followed by an accessor method on the union.
Therefore, there is a need for a system and method for joining a plurality of type hierarchies in an object oriented programming language, particularly when the inheritance tree cannot be modified, such as when a third party class library is used.
There is a further need for a system and method for performing const'ness checking in programming languages which do not directly support const'ness checking.
There is still a further need for a system and method which allows a reference class to be inserted in front of pre-existing type hierarchies, including C++ primitive data types.